package com.pengshun.modules.api.transport.controller;

import com.pengshun.config.NoRepeatSubmit;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.coal.validator.Third;
import com.pengshun.modules.api.transport.dto.TransportDto;
import com.pengshun.modules.api.transport.dto.TransportSettlementDto;
import com.pengshun.modules.api.transport.service.TransportSettlementService;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/3/19
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "货运结算")
@RequestMapping("/api/transport/settlement")
public class TransportSettlementController {

    private final TransportSettlementService transportSettlementService;

    @ApiOperation(value = "货运申请结算查询是否可以申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderAllotTransportId", value = "货运id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/apply")
    @Authorization
    public BaseResult apply(@ApiIgnore @CurrUserInfo User user, @ApiIgnore   TransportDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportSettlementService.apply(para);
        return res;
    }
    @ApiOperation(value = "货运申请结算查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderAllotTransportId", value = "货运id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "查询传1 重新申请传2", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/find")
    @Authorization
    public BaseResult find(@ApiIgnore @CurrUserInfo User user, @ApiIgnore   TransportDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportSettlementService.find(para);
        return res;
    }

    @ApiOperation(value = "货运结算申请保存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mineHairNum", value = "实发数量", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "arrivalNum", value = "到货数量", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "issuePrice", value = "发布价格", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "totalPrice", value = "总运费", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "profit", value = "盈利", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "transportId", value = "货运id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "suerUserId", value = "确认人id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/save")
    @Authorization
    @NoRepeatSubmit
    public BaseResult save(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) TransportSettlementDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportSettlementService.save(para);
        return res;
    }

    @ApiOperation(value = "运输公司结算列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = " 1待结算、2已结算", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/list")
    @Authorization
    public BaseResult list(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportSettlementService.list(para);
        return res;
    }
    @ApiOperation(value = "商贸公司结算列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = " 1待结算、2已结算", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/merchant-list")
    @Authorization
    public BaseResult merchantList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportSettlementService.merchantList(para);
        return res;
    }

    @ApiOperation(value = "货运结算详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/detil")
    @Authorization
    public BaseResult detil(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) TransportSettlementDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportSettlementService.detil(para);
        return res;
    }
    @ApiOperation(value = "货运结算退回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "casue", value = "原因", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "transportSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/back")
    @Authorization
    public BaseResult update(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Third.class}) TransportSettlementDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportSettlementService.back(para);
        return res;
    }
    @ApiOperation(value = "商家确认")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/sure")
    @Authorization
    @NoRepeatSubmit
    public BaseResult sure(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) TransportSettlementDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = transportSettlementService.sure(para);
        return res;
    }
}
